﻿using System.Text;
using System.Globalization;

namespace VideoClipNameHelper
{
    public class RemoveAccents
    {
        private static TextInfo ti = null;
        //--------------------------------------
        static RemoveAccents()
        {
            ti = new CultureInfo("en-US", false).TextInfo;
        }
        //--------------------------------------
        public static string Do(string sIn)
        {
            string so = "";
            //
            string s = sIn.Normalize(NormalizationForm.FormD);

            for (int ich = 0; ich < s.Length; ich++)
            {
                if (' ' == s[ich])
                {
                    continue;
                }
                else if ('æ' == s[ich])
                {
                    so += "ae";
                    continue;
                }
                else if ('Æ' == s[ich])
                {
                    so += "Ae";
                    continue;
                }
                else if ('Œ' == s[ich])
                {
                    so += "oe";
                    continue;
                }
                else if ('œ' == s[ich])
                {
                    so += "Oe";
                    continue;
                }
                else if ('ß' == s[ich])
                {
                    so += "ss";
                    continue;
                }
                else if ('ẞ' == s[ich])
                {
                    so += "Ss";
                    continue;
                }
                //
                UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(s[ich]);
                //if (uc != UnicodeCategory.NonSpacingMark)
                if (uc == UnicodeCategory.LowercaseLetter || uc == UnicodeCategory.UppercaseLetter || uc == UnicodeCategory.DecimalDigitNumber)
                {
                    so += s[ich];
                }
            }
            //
            return so;
        }
        //--------------------------------------
        //--------------------------------------
        public static string DoWithoutDuplicates(string sIn)
        {
            sIn = Do(sIn);
            //
            string sOut = "";
            //
            char prevChar = (char)(0xE000);
            for(int i=0; i<sIn.Length; i++)
            {
                if(prevChar == sIn[i])
                {
                    continue;
                }
                else
                {
                    prevChar = sIn[i];
                    sOut += sIn[i];
                }
                //
                //
            }
            //
            return sOut;
        }
    }
}
